package com.huang.lesson02;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

public class TestClient {
    public static void main(String[] args) {
        OutputStream outputStream=null;
        Socket socket =null;
        //需要知道对方地址
        try {
            InetAddress address = InetAddress.getByName("127.0.0.1");
            int port=9999;
             socket = new Socket(address,port);
             //发送消息
             outputStream = socket.getOutputStream();
            outputStream.write("nihao".getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
}
